package com.net.xpay.common.manager.impl.notify;

import com.google.common.base.Preconditions;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.xpay.common.dao.notify.ChargeRecordNotifyRecordMapper;
import com.net.xpay.common.domain.notify.ChargeRecordNotifyRecord;
import com.net.xpay.common.manager.notify.ChargeRecordNotifyRecordManager;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.model.search.ChargeRecordNotifyRecordSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;


@Component
public class ChargeRecordNotifyRecordManagerImpl extends AbstractManager<ChargeRecordNotifyRecord> implements ChargeRecordNotifyRecordManager{

    @Autowired
    private ChargeRecordNotifyRecordMapper mapper;


    @Override
    protected BasicMapper<Long, ChargeRecordNotifyRecord> getMapper() {
        return mapper;
    }

    @Override
    public int deleteFinishedRecord(LocalDateTime deadline) {
        Preconditions.checkArgument(deadline != null);
        return mapper.deleteFinishedRecord(deadline);
    }

    @Override
    public List<Long> listWaitNotifyRecordIds(long limitCount) {
        List<Long> ids = mapper.listWaitNotifyRecordIds(limitCount);
        return ids == null ? new ArrayList<>() : ids;
    }

    @Override
    public List<ChargeRecordNotifyRecord> search(ChargeRecordNotifyRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(ChargeRecordNotifyRecordSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }
}
